$(function () {
  $(".input_sub").on('click', () => {
    const username = $(".input_txt").val();
    const password = $(".input_pass").val();

    console.log(username, password);
    if (!username.trim() || !password.trim()) {
      // alert('登录名或是密码不能为空');
      $('.modal').modal('show');
      $(".modal-body p").text('登录名或是密码不能为空');
      return;
    }

    $.ajax({
      type: "post",
      url: window.BigNew.user_login,
      data: { username, password },
      success: function (response) {
        if (response.code == 200) {
          // alert('登录成功');
          window.localStorage.setItem('bignews_token', response.token);
          $('.modal').modal('show');
          $(".modal-body p").text('登录成功');
          $(".btn-primary").on('click', () => {
            $('.modal').modal('hide');
            window.location.href = './index.html';
          });
          // window.location.href = './index.html';
        } else {
          // alert('用户名或是密码错误');
          $('.modal').modal('show');
          $(".modal-body p").text('用户名或是密码错误');
        }
      }
    });
  });

  $(".btn-primary").on('click', () => {
    $('.modal').modal('hide');
  });
});